package com.chester.gateway.config;

import com.chester.gateway.filter.global.TokenFilter;
import com.chester.gateway.filter.keyresolver.RemoteAddressKeyResolver;
import com.chester.gateway.filter.factory.ElapsedGatewayFilterFactory;
import org.springframework.context.annotation.Bean;

/**
 * @author chester7cheng
 */
@org.springframework.context.annotation.Configuration
public class Configuration {
//    @Bean
//    RouteLocator routeLocator(RouteLocatorBuilder builder) {
//        RouteLocator routeLocator = builder.routes().route(
//                r -> r.path("/throttle/ecfr/**")
//                        .filters(
//                                f -> f.stripPrefix(2)
//                                        .filter(new RateLimitByIpGatewayFilter(10, 1, Duration.ofSeconds(1L))))
//                        .uri("lb://EUREKA-CONSUMER-FEIGN-RABBITMQ")
//                        .order(0)
//                        .id("throttle-ecfr-class")
//        ).build();
//
//        return routeLocator;
//    }

    @Bean
    public TokenFilter tokenFilter() {
        return new TokenFilter();
    }

    @Bean
    public ElapsedGatewayFilterFactory elapsedGatewayFilterFactory(){
        return new ElapsedGatewayFilterFactory();
    }

    @Bean
    public RemoteAddressKeyResolver remoteAddressKeyResolver(){
        return new RemoteAddressKeyResolver();
    }

}
